#include"progress.h"

void DownLoad()
{
    srand((unsigned int)time(0));
    int total = FILESIZE;
    int once = 0;
    while(once <= total)
    {
        usleep(5000);
        once += rand()%(1024*1024);
        double num = once*1.0 / total *100;
        if((int)num == 100)
        {
            num = 100.00;
        }
        ProgressBar(num);
    }
}

char bar[NUM] = {0};
void ProgressBar(double count)
{
   static int cnt = 0;
   int num = (int)count;
   const char *lable = "|/-\\";
   if(num == 0)
   {
       bar[0] = HEAD;
   }
   printf("[%-100s][%6.2f%%][%c]\r", bar, count, lable[cnt%4]);
   fflush(stdout);

   bar[num] = BODY;
   if(num <100)
   {
       bar[num+1] = HEAD;
   }
   else 
   {
       printf("\n");
   }
   ++cnt;
}
